#!/bin/bash

CMD_SED="/bin/sed"
CMD_DATE="/bin/date"
CMD_ECHO="/bin/echo"
CMD_AWK="/usr/bin/awk"
CMD_LOG="/usr/bin/logger"
CMD_BC="/usr/bin/bc"
CMD_WC="/usr/bin/wc"
CMD_CURL="/usr/bin/curl"

TIMESTAMP=$(${CMD_DATE} +%s)

pid=`ps -eaf |grep marrakesh.xml | grep -v grep |awk '{print $2}'`
pidtc=`ps -eaf |grep templatecache.xml | grep -v grep |awk '{print $2}'`

thread=`ps axo pid,nlwp |egrep $pid | awk '{print $2}'`
threadtc=`ps axo pid,nlwp |egrep $pidtc | awk '{print $2}'`

busy=`curl -s 'http://localhost/server-status?auto' |egrep "BusyWorkers" |awk '{print $2}'`
idle=`curl -s 'http://localhost/server-status?auto' |egrep "IdleWorkers" |awk '{print $2}'`

${CMD_ECHO} "UOLGRAPH check_thread_geral_tc 10 ${HOSTNAME} AGENTE_LASTRUN ${TIMESTAMP} t_marrakesh ${thread} t_templatecache ${threadtc} t_busy ${busy} t_idle ${idle}" | ${CMD_LOG} -p local5.info -t UOL007

